/* eslint-disable */
<template>
	<div class="roleManage">
		<div class="userCollapse" >
			<el-form class='searchform' :inline="true" :model="form" ref="form" label-width="140px">
				<el-row>
					<el-col :span="24" class="flex flex-vc rowItem">
						<el-button  @click="showcollse=!showcollse" class="showsearchBtn" type="info"
							 :icon="showcollse?'el-icon-caret-top':'el-icon-caret-bottom'"  size="mini" >{{showcollse?$t('common.collseHide'):$t('common.spread')}}</el-button>
						<span class="searchTitle flex-vc inline_flex flex-hc">{{$t('searchEaraLabel.role')}}</span>
						<div class="userCollapse_item" v-if="showcollse">
							<el-form-item :label="$t('common.roleCode')+'：'">
								<el-input v-model="form.roleCode" :placeholder="$t('common.inputPlaceholder')"></el-input>
							</el-form-item>
							<el-form-item :label="$t('common.roleName')+'：'">
								<el-input v-model="form.roleName" :placeholder="$t('common.inputPlaceholder')"></el-input>
							</el-form-item>
							<el-form-item :label="$t('common.roleType')+'：'">
								<el-select v-model="form.roleType" :placeholder="$t('common.selectPlaceholder')" clearable>
									<el-option v-for="(item,index) in roleTypeDic" :key="index" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
							<el-form-item :label="$t('common.roleStatus')+'：'">
								<el-select v-model="form.roleStatus" :placeholder="$t('common.selectPlaceholder')" >
									<el-option v-for="(item,index) in statusDic" :key="index" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
							<el-form-item :label="$t('common.subsysName')+'：'">
								<el-input  v-model="form.subsysName" :placeholder="$t('common.inputPlaceholder')"></el-input>
							</el-form-item>
							<el-form-item :label="$t('common.isSpecial1')+'：'" >
								<el-select v-model="form.isSpecial" :placeholder="$t('common.selectPlaceholder')" >
									<el-option v-for="(item,index) in selectSection" :key="index" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
						</div>
						<div class="userCollapse_hide" v-if="!showcollse">
							<span>{{$t('common.roleCode')}}:</span><strong>【{{form.roleCode?form.roleCode:$t('common.all')}}】</strong>
							<span>{{$t('common.roleName')}}:</span><strong>【{{form.roleName?form.roleName:$t('common.all')}}】</strong>
							<span>{{$t('common.roleType')}}:</span><strong>【{{getSearchAreaName('roleType')}}】</strong>
							<span>{{$t('common.roleStatus')}}:</span><strong>【{{getSearchAreaName('roleStatus')}}】</strong>
							<span>{{$t('common.subsysName')}}:</span><strong>【{{form.subsysName?form.subsysName:$t('common.all')}}】</strong>
							<span>{{$t('common.isSpecial1')}}:</span><strong>【{{getSearchAreaName('isSpecial')}}】</strong>
						</div>
					</el-col>

				</el-row>
			</el-form>

		</div>
		<!--操作区域-->
		<el-row>
			<el-col :span="18">
				<div class="operateBtn">
					<el-button   @click="addnew()" >{{$t('modules.roleManage.add')}}</el-button>
					<el-button  @click="beforeupdate()" >{{$t('modules.roleManage.modify')}}</el-button>
					<el-button  @click="batchDisabled">{{$t('modules.roleManage.statusChoice')}}</el-button>
					<el-button   @click="appendResource" >{{$t('modules.roleManage.connectResource')}}</el-button>
					<el-button  @click="appendModule" >{{$t('modules.roleManage.connectModule')}}</el-button>
				</div>
			</el-col>
			<el-col :span="6">
				<div class="searchBtn">
					<el-button type="primary" @click="onSearch" >{{$t('common.searchBtn')}}</el-button>
					<el-button type="primary" @click="resetSearch" >{{$t('common.resetBtn')}}</el-button>
				</div>
			</el-col>
		</el-row>
		<!--系统信息列表-->
		<el-table class="data-list "  v-loading="loadind" ref="multipleTable" :data="dataList" border @selection-change="selectChange" @row-dblclick="update" highlight-current-row  >
			<el-table-column  type="selection" width="55"></el-table-column>
			<el-table-column v-for="item in tableVisibleArr" :key="item.prop" :prop="item.prop" :label="item.label"  align="center"  show-overflow-tooltip :formatter="formatter"></el-table-column>
		</el-table>
		<div class="tablebottom" style="position:relative;">
			<el-pagination
		      @size-change="pageSizeChange"
		      @current-change="handleCurrentChangePage"
		      :current-page="pagination.pageNum"
		      :page-sizes="[10,20, 50, 100, 200]"
		      :page-size="pagination.pageSize"
		      layout="->,prev, pager, next, jumper, sizes,total"
		      :total="pagination.totalSize">
		    </el-pagination>
		    <!-- 自定义表格字段组件 -->
		    <defined-table storageName="basp_roleManage" :headArr="headArr" :selectArr="tableVisibleArr" @saveAutoDefinedTable="saveAutoDefinedTable"></defined-table>
		</div>

		<!--新增修改基本信息-->
		<el-dialog class="newlyForm" :title="titleFlag==1?$t('modules.roleManage.addNewInfo'):$t('modules.roleManage.modifyInfo')" :visible.sync="newlyFormVisible" :close-on-click-modal="false" width="50%" :before-close="closeFunction"  @close="closeDialog">
			<el-row>
			    <el-col :span="22">
			  		<el-form :rules="rules"  :inline="false" :model="roleInfoForm" ref="roleInfoForm" label-width="150px">
			  			<el-form-item :label="$t('common.subsysName')+'：'" prop="subsysName">
							<el-autocomplete   :disabled="titleFlag!=1"
								 v-model="roleInfoForm.subsysName"  :placeholder="$t('common.inputPlaceholder')"
						      :fetch-suggestions="$subsysNameSelect"
						      @select="subsysCodeSleSelect" :trigger-on-focus="false"
						    ></el-autocomplete >
						</el-form-item>
						<!--<el-form-item label="角色ID："  >
							<el-input :disabled="true" v-model="roleInfoForm.roleId" placeholder="系统自动生成"></el-input>
						</el-form-item>-->
						<el-form-item :label="$t('common.roleCode')+'：'"  prop="roleCode">
							<el-input   :disabled="titleFlag!=1" v-model="roleInfoForm.roleCode"  @change="roleInfoForm.roleCode=$checkTextValidate(roleInfoForm.roleCode)"  placeholder="如：88888888+rolecodeDemo"></el-input>
						</el-form-item>
						<el-form-item :label="$t('common.roleName')+'：'" prop="roleName">
							<el-input :maxlength="128"   v-model="roleInfoForm.roleName"  @change="roleInfoForm.roleName=$checkTextValidate(roleInfoForm.roleName)" :placeholder="$t('common.inputPlaceholder')"></el-input>
						</el-form-item>
						<el-form-item :label="$t('common.roleDesc')+'：'" prop="roleDesc">
							<el-input :maxlength="128"  type="textarea" :rows="2"   @change="roleInfoForm.roleDesc=$checkTextValidate(roleInfoForm.roleDesc)" v-model="roleInfoForm.roleDesc" :placeholder="$t('common.inputPlaceholder')"></el-input>
						</el-form-item>
						<el-form-item :label="$t('common.roleType')+'：'" prop="roleType">
							<el-select  :disabled="titleFlag!=1" v-model="roleInfoForm.roleType" :placeholder="$t('common.selectPlaceholder')" >
								<el-option v-for="(item,index) in roleTypeDic" :key="index" :label="item.label" :value="item.value"></el-option>
							</el-select>
						</el-form-item>
						<el-form-item :label="$t('common.isSpecial1')+'：'" prop="isSpecial">
							<el-select  v-model="roleInfoForm.isSpecial" :placeholder="$t('common.selectPlaceholder')" >
								<el-option v-for="(item,index) in selectSection" :key="index" :label="item.label" :value="item.value"></el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="ETL_ID：">
							<el-input :maxlength="128" @change="roleInfoForm.etlRoleId=$getTextNumber(roleInfoForm.etlRoleId)"  v-model="roleInfoForm.etlRoleId" :placeholder="$t('common.inputPlaceholder')"></el-input>
						</el-form-item>
				    </el-form>
		        </el-col>
			</el-row>
			<div slot="footer" class="dialog-footer">
				<el-button @click="giveupFun('newlyFormVisible')">{{$t('common.giveUp')}}</el-button>
				<el-button type="primary" @click="submitForm">{{$t('common.save')}}</el-button>
			</div>
		</el-dialog>
		<!--角色绑定资源-->
		<el-dialog class="appendResource" :title="$t('modules.roleManage.connectResource')" :visible.sync="appendResourceVisible" :close-on-click-modal="false"  width="50%" >
			<el-form  :rules="rules"  :inline="true" :model="dataRoleRow" ref="dataRoleRow" >
				<el-form-item :label="$t('common.subsysName')+'：'" >
					<el-input  disabled v-model="dataRoleRow.subsysName" :placeholder="$t('common.inputPlaceholder')"></el-input>
				</el-form-item>
				<el-form-item :label="$t('common.roleName')+'：'" >
					<el-input  disabled v-model="dataRoleRow.roleName" :placeholder="$t('common.inputPlaceholder')"></el-input>
				</el-form-item>
			</el-form>
			<el-row>
				<!--可选资源列表-->
			  <el-col :span="10">
			  		<div class="marginB10 font-bold">{{$t('modules.roleManage.canSelectDetail')}}</div>
			  		<el-table v-loading="loadind1"  ref="resourceList" :data="resourceList" border max-height="500"  style="width: 100%" @selection-change="selectAddListChange" >
			  		 	<el-table-column  type="selection" width="55"></el-table-column>
			  		 	 <el-table-column prop="resourceName" :label="$t('common.resourceName')"   show-overflow-tooltip></el-table-column>
					    <el-table-column prop="ownerSysName" :label="$t('common.ownerSysName')"  show-overflow-tooltip> </el-table-column>
					</el-table>
					<el-pagination
				      @size-change="pageSizeChange1"
				      @current-change="handleCurrentChangePage1"
				      :current-page="pagination1.pageNum"
				      :page-sizes="[10,20, 50, 100, 200]"
				      :page-size="pagination1.pageSize"
				      layout="->,prev, pager, next, sizes,total"
				      :total="pagination1.totalSize">
				    </el-pagination>
			  </el-col>
			  <!--操作按钮-->
			  <el-col :span="4" class="alignC">
			  	<div>
			  		<el-button  type="primary"  @click="addToRight" >{{$t('common.add')}}<i class="el-icon-arrow-right"></i></el-button>
			  	</div>
			  	<div>
			  		<el-button  type="danger"  @click="delfromRight" > <i class="el-icon-arrow-left"></i> {{$t('common.remove')}}</el-button>
			  	</div>

			  </el-col>
			  <!--已添加资源列表-->
			  <el-col :span="10">
			  		<div class="marginB10 font-bold">{{$t('modules.roleManage.connectedDetail')}}</div>
			  		<el-table v-loading="loadind2" ref="selectResorceList"  :data="selectResorceList" max-height="500"   border  style="width: 100%"  @selection-change="selectDelListChange">
			  		 	<el-table-column  type="selection" width="55"></el-table-column>
					    <el-table-column prop="resourceName" :label="$t('common.resourceName')"  show-overflow-tooltip> </el-table-column>
					    <el-table-column prop="ownerSysName" :label="$t('common.ownerSysName')"  show-overflow-tooltip></el-table-column>
					</el-table>
					<el-pagination
				      @size-change="pageSizeChange2"
				      @current-change="handleCurrentChangePage2"
				      :current-page="pagination2.pageNum"
				      :page-sizes="[10,20, 50, 100, 200]"
				      :page-size="pagination2.pageSize"
				      layout="->,prev, pager, next, sizes,total"
				      :total="pagination2.totalSize">
				    </el-pagination>
			  </el-col>
			</el-row>
		</el-dialog>
		<!--角色绑定模块-->
		<append-module :visible="appendModuleVisible" :formInfo="dataRoleRow" @close="appendModuleVisible=false" @giveUp="giveupFun('appendModuleVisible')" @saveModuleSelected="saveModuleSelected"></append-module>
	</div>
</template>
<script>
import definedTable from "../components/definedTable"
import appendModule from "../components/appendModule"
import {
    Message, Notification, MessageBox, Loading
} from 'element-ui'
export default {
	name: 'roleManage',
    components: {
        definedTable,
        appendModule
    },
    props:['pageId'],
    data () {
        return {
            dataRoleRow: {
            },
            showcollse: false,
            form: {
                subsysName: '',
                roleCode: '',
                roleName: '',
                roleType: '',
                roleStatus: 1,
                isSpecial: ''
            },
            roleInfoForm: {
                roleId: '',
                roleCode: '',
                roleName: '',
                roleDesc: '',
                isSpecial: '',
                roleType: '',
                subsysCode: '',
                etlRoleId: ''
            },
            titleFlag: 1,
            rules: {
		        roleCode: [
		            { required: true, message: this.$t('validateWornText.inputRoleCode'), trigger: 'blur' }
		        ],
                roleName: [
		            { required: true, message: this.$t('validateWornText.inputRoleName'), trigger: 'blur' }
		        ],
		        roleDesc: [
		            { required: true, message: this.$t('validateWornText.inputRoleDesc'), trigger: 'blur' }
		        ],
                isSpecial: [
		            { required: true, message: this.$t('validateWornText.selectIsSpecial'), trigger: 'change' }
		        ],
                roleType: [
		            { required: true, message: this.$t('validateWornText.selectRoleType'), trigger: 'change' }
		        ],
		        subsysName: [
		            { required: true, message: this.$t('validateWornText.inputSubsysName'), trigger: 'blur' }
		        ]
            },
            selectSection: [
                { value: 0, label: this.$t('common.not') }, { value: 1, label: this.$t('common.is') }
            ],
            resourceNameList: [],
            statusDic: [
                { value: 1, label: (window.sessionStorage.getItem('lang') === 'zh-CN') ? "启用" : 'enabled' },
			    { value: 0, label: (window.sessionStorage.getItem('lang') === 'zh-CN') ? "禁用" : 'disabled' }
            ], // 状态字典
            roleTypeDic: [
                { value: 0, label: (window.sessionStorage.getItem('lang') === 'zh-CN') ? "管理员" : 'Administrators' },
                { value: 1, label: (window.sessionStorage.getItem('lang') === 'zh-CN') ? "子管理员" : 'Secondary Administrator' },
                { value: 2, label: (window.sessionStorage.getItem('lang') === 'zh-CN') ? "普通用户" : 'Ordinary users' }
            ], // 角色类型
            pagination: {
                totalSize: 0,
                pageSize: 10,
                pageNum: 1,
                totalPage: 0
            },
            dataList: [],
            loadind: false,
            multipleSelection: [],
            chooseSelectionArr: [],
            newlyFormVisible: false,
            appendResourceVisible: false,
            appendModuleVisible: false,
	        addSelectMultipleSelection: [], // 将要勾选到右侧列表的列表
	        delSelectMultipleSelection: [], // 将要从右侧取消选择的列表
	        selectResorceList: [], // 已选资源
	        resourceList: [], // 可选资源
	       	pagination1: {
                totalSize: 0,
                pageSize: 10,
                pageNum: 1,
                totalPage: 0
            },
            loadind1: false,
            pagination2: {
                totalSize: 0,
                pageSize: 10,
                pageNum: 1,
                totalPage: 0
            },
            loadind2: false,
	       	headArr: [
                { prop: "systemName", label: this.$t('common.systemName'), index: 0 },
                { prop: "subsysName", label: this.$t('common.subsysName'), index: 1 },
                { prop: "roleId", label: this.$t('common.roleId'), index: 2 },
                { prop: "roleCode", label: this.$t('common.roleCode'), index: 3 },
                { prop: "roleName", label: this.$t('common.roleName'), index: 4 },
                { prop: "roleType", label: this.$t('common.roleType'), index: 5 },
                { prop: "isSpecial", label: this.$t('common.isSpecial1'), index: 6 },
                { prop: "status", label: this.$t('common.roleStatus'), index: 7 },
                { prop: "lastUpdator", label: this.$t('common.lastUpdator'), index: 8 },
                { prop: "lastUpdateTm", label: this.$t('common.lastUpdateTm'), index: 9 },
                { prop: "creator", label: this.$t('common.creator'), index: 10 },
                { prop: "createTm", label: this.$t('common.createTm'), index: 11 }
            ],
            tableVisibleArr: []
        }
    },
    beforeCreate () {
    },
    mounted () {
    	console.log('this.$store.getters.btns[this.pageId]',this.$store.getters.btns[this.pageId])
        var pageObj = localStorage.getItem('basp_roleManage') // 捞出缓存中的该页面的表格配置
        if (pageObj) {
            var obj = JSON.parse(pageObj)
            if (sessionStorage.getItem('userName')) {
    			this.saveAutoDefinedTable(obj[sessionStorage.getItem('userName')])
    		} else {
    			this.tableVisibleArr = this.$deepCopy(this.headArr, [])
    		}
    	} else {
    		this.tableVisibleArr = this.$deepCopy(this.headArr, [])
    	}
        this.searchHttp()
    },
    methods: {
        saveAutoDefinedTable (arr) { // 配置表格可见的选项
            var temp = []
            for (var i = 0; i < arr.length; i++) {
                temp.push(this.headArr[arr[i]])
            }
            this.tableVisibleArr = temp
        },
        selectChange (val) {
            this.multipleSelection = val
        },
        subsysCodeSleSelect (item) {
            this.roleInfoForm.subsysCode = item.code
        },
        searchHttp () {
            var param = {
                subsysName: this.form.subsysName,
                roleCode: this.form.roleCode,
                roleName: this.form.roleName,
                roleType: this.form.roleType,
                roleStatus: this.form.roleStatus,
                isSpecial: this.form.isSpecial,
                pageSize: this.pagination.pageSize,
                pageNum: this.pagination.pageNum
            }
            this.loadind = true
            var that = this
            this.$httpExt().post('/dev-basp-system/role/queryList', param)
                .then((response) => {
                    this.loadind = false
                    var body = response.result
                    this.pagination.totalSize = body.totalSize
                    this.dataList = body.data
                    var tempSelectCurrent = []
                    if (that.chooseSelectionArr.length > 0) {
                        for (var i = 0; i < that.dataList.length; i++) {
                            for (var k = 0; k < that.chooseSelectionArr.length; k++) {
                                var id1 = that.chooseSelectionArr[k].roleId
                                var id2 = that.dataList[i].roleId
                                if (id1 === id2) {
                                    tempSelectCurrent.push(that.dataList[i])
                                    that.chooseSelectionArr.splice(k, 1)
                                    break
                                }
                            }
                        }
                    }
                    this.$nextTick(() => {
                        that.toggleSelection(tempSelectCurrent, 'multipleTable')
                    })
                }, (response) => {
                    this.loadind = false
                    Notification.error({
                        title: this.$t('common.exception'),
                        message: response.msg ? response.msg : this.$t('common.exceptionWornText')
                    })
                })
        },
        toggleSelection (rows, val) {
            if (rows.length) {
	          rows.forEach(row => {
	            this.$refs[val].toggleRowSelection(row)
	          })
	        } else {
	          this.$refs[val].clearSelection()
	        }
	    },
        handleCurrentChangePage (val) {
            this.chooseSelectionArr = this.chooseSelectionArr.concat(this.multipleSelection)
            this.pagination.pageNum = val
            this.searchHttp()
        },
        pageSizeChange (val) {
            this.chooseSelectionArr = this.chooseSelectionArr.concat(this.multipleSelection)
            this.pagination.pageNum = 1
            this.pagination.pageSize = val
            this.searchHttp()
        },
        resetSearch () { // 重置搜索域
            this.form = {
                subsysName: '',
                roleCode: '',
                roleName: '',
                roleType: '',
                roleStatus: 1,
                isSpecial: ''
            }
        },
        onSearch () {
            this.multipleSelection = []// 清空当前页面勾选项
            this.chooseSelectionArr = []// 清空页面所有勾选项
            this.pagination.pageNum = 1
            this.searchHttp()
        },
        batchDisabled () {
            var tempAllselectData = this.$deepCopy(this.chooseSelectionArr, [])
            tempAllselectData = tempAllselectData.concat(this.multipleSelection)
            if (tempAllselectData.length > 0) {
                var text
                if (tempAllselectData[0].status === 1) {
                    text = this.$t('modules.roleManage.disabledTip')
                } else {
                    text = this.$t('modules.roleManage.confirmStart')
                }
                this.$confirm(text, this.$t('common.tip'), {
                    confirmButtonText: this.$t('common.submitOption'),
                    cancelButtonText: this.$t('common.cancelOption')
                }).then(() => {
                    var urlH = '/dev-basp-system/role/state'
                    let loadingInstance = Loading.service({ fullscreen: true })
                    var param = []
                    for (var i = 0; i < tempAllselectData.length; i++) {
                        param.push({
                            roleId: tempAllselectData[i].roleId,
                            status: tempAllselectData[0].status === 1 ? 0 : 1
                        })
                    }
                    var that = this
                    this.$httpExt().post(urlH, param)
                        .then((response) => {
                            loadingInstance.close()
                            that.onSearch()
                            this.$message({
                                message: this.$t('modules.roleManage.dataSaveSuccess'),
                                type: 'success'
                            })
                        }, (response) => {
                            loadingInstance.close()
                            Notification.error({
                                title: this.$t('common.exception'),
                                message: response.msg ? response.msg : this.$t('common.exceptionWornText')
                            })
                        })
                }).catch(() => {
                })
            } else {
                MessageBox({
                    message: (window.sessionStorage.getItem('lang') === 'zh-CN') ? '请至少选择一条数据进行操作!' : 'Please select at least one data for operation!',
                    confirmButtonText: this.$t('common.iknow')
                })
            }
        },
        closeDialog () { // 关闭新增，修改模态框
            this.newlyFormVisible = false
            this.$refs['roleInfoForm'].resetFields()// 重置表单
            this.roleInfoForm = {
                roleId: '',
                roleCode: '',
                roleName: '',
                roleDesc: '',
                isSpecial: '',
                roleType: '',
                subsysCode: '',
                etlRoleId: ''
            }
	    },
	    closeFunction (done) {
	    	this.giveupFun('newlyFormVisible')
	    },
	    appendModule () { // 绑定模块
	    	if (this.multipleSelection.length > 1) {
                MessageBox({
                    message: (window.sessionStorage.getItem('lang') === 'zh-CN') ? '请选择一条数据进行操作!' : 'Please select only one data for operation!',
                    confirmButtonText: this.$t('common.iknow')
                })
                return
            } else if (this.multipleSelection.length === 1) {
                if (this.multipleSelection[0].status === 0) {
                    this.$message({
				          message: this.$t('modules.roleManage.currentRoleStatusTip'),
				          type: 'warning'
				    })
                    return
                }
                this.dataRoleRow = this.$deepCopy(this.multipleSelection[0])
            } else {
                MessageBox({
                    message: (window.sessionStorage.getItem('lang') === 'zh-CN') ? '请至少选择一条数据进行操作!' : 'Please select at least one data for operation!',
                    confirmButtonText: this.$t('common.iknow')
                })
                return
            }
	    	this.appendModuleVisible = true
	    },
	    saveModuleSelected (currentCheckedKeys) { // 保存选择的模块
	    	if (currentCheckedKeys.length) {
	    		var param = {
                    roleId: this.dataRoleRow.roleId,
                    moduleIds: currentCheckedKeys
                }
                var urlH = "/dev-basp-system/role/saveRoleModule"
                let loadingInstance = Loading.service({ fullscreen: true })
                this.$httpExt().post(urlH, param)
                    .then((response) => {
                        loadingInstance.close()
                        this.$message({
				          message: response.msg ? response.msg : this.$t('modules.roleManage.appendModuleSuccess'),
				          type: 'success'
				    })
				    this.appendModuleVisible = false
                    }, (response) => {
                        loadingInstance.close()
                        Notification.error({
                            title: this.$t('common.exception'),
                            message: response.msg ? response.msg : this.$t('common.exceptionWornText')
                        })
                    })
	    	} else {
	    		this.$message({
			          message: this.$t('modules.roleManage.emptySelectTip'),
			          type: 'warning'
			    })
	    	}
	    },
	    addnew () {
	    	this.newlyFormVisible = true
	    	this.titleFlag = 1
	    },
	    // 修改
        update (row) {
            this.roleInfoForm = {
                roleId: row.roleId,
                roleCode: row.roleCode,
                roleName: row.roleName,
                roleDesc: row.roleDesc,
                isSpecial: row.isSpecial,
                roleType: row.roleType,
                subsysCode: row.subsysCode,
                subsysName: row.subsysName,
                etlRoleId: row.etlRoleId
            }
            this.titleFlag = 2
            this.newlyFormVisible = true
        },
        submitForm () {
            this.$refs['roleInfoForm'].validate((valid) => {
                if (valid) {
                    var urlH = this.titleFlag === 1 ? '/dev-basp-system/role/add' : '/dev-basp-system/role/update'
                    var param = {
                        roleId: this.roleInfoForm.roleId,
                        roleCode: this.roleInfoForm.roleCode,
                        roleName: this.roleInfoForm.roleName,
                        roleDesc: this.roleInfoForm.roleDesc,
                        isSpecial: this.roleInfoForm.isSpecial,
                        roleType: this.roleInfoForm.roleType,
                        subsysCode: this.roleInfoForm.subsysCode,
                        etlRoleId: this.roleInfoForm.etlRoleId
                    }
                    let loadingInstance = Loading.service({ fullscreen: true })
                    this.$httpExt().post(urlH, param)
                        .then((response) => {
                            this.newlyFormVisible = false
                            this.$message({
					          message: response.msg ? response.msg : this.$t('modules.roleManage.saveSuccess'),
					          type: 'success'
					    })
                            this.onSearch()
                            loadingInstance.close()
                        }, (response) => {
                            loadingInstance.close()
                            Notification.error({
                                title: this.$t('common.exception'),
                                message: response.msg ? response.msg : this.$t('common.exceptionWornText')
                            })
                        })
                } else {
                    return false
                }
            })
        },
        // 判断勾选
        beforeupdate () {
            if (this.multipleSelection.length > 1) {
                MessageBox({
                    message: (window.sessionStorage.getItem('lang') === 'zh-CN') ? '请选择一条数据进行操作!' : 'Please select only one data for operation!',
                    confirmButtonText: this.$t('common.iknow')
                })
            } else if (this.multipleSelection.length === 1) {
                if (this.multipleSelection[0].status === 0) {
                    this.$message({
                        message: this.$t('modules.roleManage.modifyTip'),
                        type: 'warning'
                    })
                    return
                }
                this.update(this.multipleSelection[0])
            } else {
                MessageBox({
                    message: (window.sessionStorage.getItem('lang') === 'zh-CN') ? '请至少选择一条数据进行操作!' : 'Please select at least one data for operation!',
                    confirmButtonText: this.$t('common.iknow')
                })
            }
	    },
	    /* 资源绑定的相关操作 */
	    appendResource () { // 绑定资源
	    	if (this.multipleSelection.length > 1) {
                MessageBox({
                    message: '请选择一条记录进行操作！',
                    confirmButtonText: '我知道了'
                })
                return
            } else if (this.multipleSelection.length === 1) {
                if (this.multipleSelection[0].status === 0) {
                    this.$message({
				          message: '选择的角色状态为禁用，不可关联资源',
				          type: 'warning'
				    })
                    return
                }
                if (this.multipleSelection[0].isSpecial === 0) {
                    this.$message({
				          message: '是否关联数据权限为否，不可关联资源',
				          type: 'warning'
				    })
                    return
                }
                this.dataRoleRow = this.$deepCopy(this.multipleSelection[0])
            } else {
                MessageBox({
                    message: (window.sessionStorage.getItem('lang') === 'zh-CN') ? '请选择一条数据进行操作!' : 'Please select only one data for operation!',
                    confirmButtonText: this.$t('common.iknow')
                })
                return
            }
            this.pagination2.pageNum = 1
	    	this.appendResourceVisible = true
	    	this.searchAllResourceList()
	    	this.searchChoosedResourceList()
	    },
	    searchResourceList (status) {
	    	var urlH, param
            if (status === 0) { // 未勾选
                param = {
                    pageSize: this.pagination1.pageSize,
                    pageNum: this.pagination1.pageNum,
                    resourceStatus: status,
                    roleId: this.dataRoleRow.roleId
                }
                urlH = '/dev-basp-system/resource/selectOptional'
            } else { // 已勾选
                param = {
                    pageSize: this.pagination2.pageSize,
                    pageNum: this.pagination2.pageNum,
                    resourceStatus: status,
                    roleId: this.dataRoleRow.roleId
                }
                urlH = '/dev-basp-system/resource/selected'
            }
            status === 0 ? (this.loadind1 = true) : (this.loadind2 = true)
            this.$httpExt().post(urlH, param)
                .then((response) => {
                    status === 0 ? (this.loadind1 = false) : (this.loadind2 = false)
                    var body = response.result
                    if (status === 0) { // 未勾选
                        this.resourceList = body.data
                        this.pagination1.totalSize = body.totalSize
                    } else { // 已勾选
                        this.selectResorceList = body.data
                        this.pagination2.totalSize = body.totalSize
                    }
                }, (response) => {
                    status === 0 ? (this.loadind1 = false) : (this.loadind2 = false)
                    Notification.error({
                        title: this.$t('common.exception'),
                        message: response.msg ? response.msg : this.$t('common.exceptionWornText')
                    })
                })
	    },
	    searchAllResourceList () { // 搜索可选资源列表
	    	this.searchResourceList(0)
	    },
	    searchChoosedResourceList () { // 搜索已选资源列表
	    	this.searchResourceList(1)
	    },
	    handleCurrentChangePage1 (val) { // 可选资源列表分页
            this.pagination1.pageNum = val
            this.searchResourceList(0)
        },
        pageSizeChange1 (val) { // 可选资源列表分页
            this.pagination1.pageNum = 1
            this.pagination1.pageSize = val
            this.searchResourceList(0)
        },
        handleCurrentChangePage2 (val) { // 已选择资源列表分页
            this.pagination2.pageNum = val
            this.searchResourceList(1)
        },
        pageSizeChange2 (val) { // 已选择资源列表分页
            this.pagination2.pageNum = 1
            this.pagination2.pageSize = val
            this.searchResourceList(1)
        },
	    // 左侧列表勾选
	    selectAddListChange (val) {
            this.addSelectMultipleSelection = val
        },
        // 右侧列表勾选
        selectDelListChange (val) {
            this.delSelectMultipleSelection = val
        },
        addToRight () {
            if (this.addSelectMultipleSelection.length) {
                var submitSelect = this.$deepCopy(this.addSelectMultipleSelection, []) // 提交到后台的需要移到右边的数据
                for (var i = 0; i < submitSelect.length; i++) {
                    var item = submitSelect[i]
                    var tempIndex = this.$findIndex(this.selectResorceList, item, "resourceId")
                    if (tempIndex > -1) {
                        submitSelect.splice(i, 1) // 如果右侧已存在某一个勾选项，将这个选项去掉
                        i--
                    }
                }
                var arr = []
                for (var t = 0; t < submitSelect.length; t++) {
                    arr.push(submitSelect[t].resourceId)
                }
                var that = this
                var urlH = '/dev-basp-system/roleResource/saveList'
                var param = {
                    resourceIdList: arr,
                    roleId: this.dataRoleRow.roleId
                }
                let loadingInstance = Loading.service({ fullscreen: true })
                this.$httpExt().post(urlH, param)
                .then((response) => {
                    loadingInstance.close()
                    this.$message({
                        message: response.msg ? response.msg : this.$t('modules.roleManage.saveSuccess'),
                        type: 'success'
                })
                    that.searchAllResourceList()
                that.searchChoosedResourceList()
                this.toggleSelection(this.addSelectMultipleSelection, 'resourceList')// 移动之后取消勾选
                    this.addSelectMultipleSelection = []
                }, (response) => {
                    loadingInstance.close()
                    Notification.error({
                        title: this.$t('common.exception'),
                        message: response.msg ? response.msg : this.$t('common.exceptionWornText')
                    })
                })
            }
        },
        delfromRight () { // 删除已选
            if (this.delSelectMultipleSelection.length) {
                this.$confirm(this.$t('modules.roleManage.removeTip'), this.$t('common.tip'), {
		          	confirmButtonText: this.$t('common.submitOption'),
	          		cancelButtonText: this.$t('common.cancelOption')
		        }).then(() => {
		        	var submitSelect = this.$deepCopy(this.delSelectMultipleSelection, []) // 提交到后台的需要从已选列表移除的数据
                    var arr = []
                    for (var i = 0; i < submitSelect.length; i++) {
                        arr.push({
                            resourceId: submitSelect[i].resourceId,
                            roleId: this.dataRoleRow.roleId,
                            status: 0
                        })
                    }
                    var that = this
                    var urlH = '/dev-basp-system/roleResource/state'
                    let loadingInstance = Loading.service({ fullscreen: true })
                    this.$httpExt().post(urlH, arr)
                        .then((response) => {
                            loadingInstance.close()
                            this.$message({
					          message: response.msg ? response.msg : this.$t('modules.roleManage.saveSuccess'),
					          type: 'success'
					    })
                            that.searchAllResourceList()
		    			that.searchChoosedResourceList()
                        }, (response) => {
                            loadingInstance.close()
                            Notification.error({
                                title: this.$t('common.exception'),
                                message: response.msg ? response.msg : this.$t('common.exceptionWornText')
                            })
                        })
		        }).catch(() => {
		        })
            }
        },
        getSearchAreaName (val) {
		   	switch (val) {
            case "roleStatus":
                for (var c = 0; c < this.statusDic.length; c++) {
                    if (this.form.roleStatus === this.statusDic[c].value) {
                        return this.statusDic[c].label
                    }
                }
                return this.$t('commbreakon.all')
            case "isSpecial":
                for (var e = 0; e < this.selectSection.length; e++) {
                    if (this.form.isSpecial === this.selectSection[e].value) {
                        return this.selectSection[e].label
                    }
                }
                return this.$t('common.all')
            case "roleType":
                for (let e = 0; e < this.roleTypeDic.length; e++) {
                    if (this.form.roleType === this.roleTypeDic[e].value) {
                        return this.roleTypeDic[e].label
                    }
                }
                return this.$t('common.all')
            default : return this.form[val]
		   	}
	    },
        formatter (row, column) { // 状态信息中表格展开项的code转为name
            switch (column.property) {
            case "roleType":// 角色类型
                for (var i = 0; i < this.roleTypeDic.length; i++) {
                    if (row.roleType === this.roleTypeDic[i].value) {
                        return this.roleTypeDic[i].label
                    }
                }
                return row.roleType
            case "status":// 状态
                for (var a = 0; a < this.statusDic.length; a++) {
                    if (row.status === this.statusDic[a].value) {
                        return this.statusDic[a].label
                    }
                }
                return row.status
            case "isSpecial":// 状态
                for (var b = 0; b < this.selectSection.length; b++) {
                    if (row.isSpecial === this.selectSection[b].value) {
                        return this.selectSection[b].label
                    }
                }
                return row.isSpecial
            case "lastUpdateTm":return this.$format(row.lastUpdateTm, "yyyy/MM/dd hh:mm:ss") // 修改时间
            case "createTm":return this.$format(row.createTm, "yyyy/MM/dd hh:mm:ss") // 创建时间
            default : return row[column.property]
            }
	   },
	   giveupFun (val) {
	    	this.$confirm(this.$t('modules.roleManage.giveUpEditWornTip'), this.$t('common.tip'), {
	          	confirmButtonText: this.$t('common.submitOption'),
	          	cancelButtonText: this.$t('common.cancelOption')
	        }).then(() => {
	        	this[val] = false
	        }).catch(() => {
	        })
	    }
    }
}
</script>
<style lang="less">
@import "../common/css/common.less";
.roleManage{
	.searchTitle.el-form-item__label{
		width:90px;
	}
	.el-collapse-item__header{
		font-weight: bold;
	}
	.marginB10{
		margin-bottom: 10px;
	}
}
.appendResource{
	.el-dialog{
		min-width:1050px;
	}
	.el-form .el-input,.el-textarea {
		width:300px;
	}
	.el-button.removeBtn{
		background: #FFFFFF;
		border: 1px solid #409EFF;
		border-radius: 4px;
		color:#409EFF ;
	}
	.alignC{
		padding-top: 50px;
		text-align: center;
		line-height: 55px;
		.el-button--danger{
			margin-left: 0;
		}
	}
}
</style>
